/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * <p>Project: javase - ListUserSort
 * <p>Powered by webrx On 2021-12-21 14:40:34
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ListUserSort {
    public static void main(String[] args) {
        List<User> list = new ArrayList<>(List.of(new User(1, "李四", 85), new User(21, "张三", 35), new User(3, "王五", 98), new User(2, "赵六", 65)));
        System.out.println(list);

        //根据姓名，升序
        //Collections.sort(list, (a, b) -> a.getName().compareTo(b.getName()));
        Collections.sort(list, Comparator.comparing(User::getName));
        System.out.println(list);

        //根据姓名升序
        Collections.sort(list, (a, b) -> b.getName().compareTo(a.getName()));
        System.out.println(list);

        //根据成绩，降序
        Collections.sort(list, (a, b) -> b.getScore() - a.getScore());
        System.out.println(list);

    }
}
